<template>
    <div>
        <div>
            <el-table :data="emps" size="small" border stripe>
                <el-table-column type="selection" align="left" width="50"></el-table-column>
                <el-table-column prop="name" label="姓名" fixed width="120" align="left"></el-table-column>
                <el-table-column prop="workid" label="工号" width="120" align="left"></el-table-column>
                <el-table-column prop="email" label="电子邮件" width="200" align="left"></el-table-column>
                <el-table-column prop="phone" label="电话号码" width="120" align="left"></el-table-column>
                <el-table-column prop="department.name" label="所属部门" width="120" align="left"></el-table-column>
                <el-table-column label="工资账套" align="center">
                    <template slot-scope="scope">
                        <el-tooltip v-if="scope.row.salary" placement="right">
                            <div slot="content">
                                <table>
                                    <tr>
                                        <td>基本工资</td>
                                        <td>{{scope.row.salary.basicsalary}}</td>
                                    </tr>
                                    <tr>
                                        <td>交通补助</td>
                                        <td>{{scope.row.salary.trafficsalary}}</td>
                                    </tr>
                                    <tr>
                                        <td>午餐补助</td>
                                        <td>{{scope.row.salary.lunchsalary}}</td>
                                    </tr>
                                    <tr>
                                        <td>奖金</td>
                                        <td>{{scope.row.salary.bonus}}</td>
                                    </tr>
                                    <tr>
                                        <td>养老金比率</td>
                                        <td>{{scope.row.salary.pensionper}}</td>
                                    </tr>
                                    <tr>
                                        <td>养老金基数</td>
                                        <td>{{scope.row.salary.pensionbase}}</td>
                                    </tr>
                                    <tr>
                                        <td>医疗保险比率</td>
                                        <td>{{scope.row.salary.medicalper}}</td>
                                    </tr>
                                    <tr>
                                        <td>医疗保险基数</td>
                                        <td>{{scope.row.salary.medicalbase}}</td>
                                    </tr>
                                    <tr>
                                        <td>公积金比率</td>
                                        <td>{{scope.row.salary.accumulationfundper}}</td>
                                    </tr>
                                    <tr>
                                        <td>公积金基数</td>
                                        <td>{{scope.row.salary.accumulationfundbase}}</td>
                                    </tr>
                                </table>
                            </div>
                            <el-tag>{{scope.row.salary.name}}</el-tag>
                        </el-tooltip>
                        <el-tag v-else>暂未设置</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-popover
                                placement="left"
                                width="400"
                                title="修改工资账套"
                                @show="showPop(scope.row)"
                                @hide="hidePop(scope.row)"
                                trigger="click">
                            <div>
                                <el-select size="small" v-model="selectedSalary" placeholder="请选择">
                                    <el-option
                                            v-for="item in salarys"
                                            :key="item.id"
                                            :label="item.name"
                                            :value="item.id">
                                    </el-option>
                                </el-select>
                            </div>
                            <el-button slot="reference" size="small">修改工资账套</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    style="display: flex;justify-content: flex-end;"
                    background
                    @size-change="sizeChange"
                    @current-change="currentChange"
                    layout="sizes, prev, pager, next, jumper, ->, total, slot"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: "SalSobCfg",
        data() {
            return {
                emps: [],
                salarys: [],
                selectedSalary: null,
                total: 0,
                currentPage: 1,
                currentSize: 10,
            }
        },
        mounted() {
            this.initEmps();
            this.initSalary();
        },
        methods: {
            currentChange(page) {
                this.currentPage = page;
                this.initEmps();
            },
            sizeChange(size) {
                this.currentSize = size;
                this.initEmps();
            },
            hidePop(data) {
                if (this.selectedSalary && (!data.salary  || this.selectedSalary !== data.salary.id )) {
                    this.putRequest("/salary/sobcfg/?eid=" + data.id + "&sid=" + this.selectedSalary).then(resp => {
                        if (resp) {
                            this.initEmps();
                        }
                    })
                }
            },
            showPop(date) {
                if (date.salary) {
                    this.selectedSalary = date.salary.id;
                } else {
                    this.selectedSalary = null;
                }
            },
            initSalary() {
                this.getRequest("/salary/sobcfg/sob/").then(resp => {
                    if (resp) {
                        this.salarys = resp;
                    }
                })
            },
            initEmps() {
                this.getRequest("/salary/sobcfg/?page=" + this.currentPage + "&size=" + this.currentSize).then(resp => {
                    if (resp) {
                        this.emps = resp.data;
                        this.total = resp.total;
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>